package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.PurchaseRecords;
import com.ruoyi.system.service.IPurchaseRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购记录管理Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/records1")
public class PurchaseRecordsController extends BaseController {
    @Autowired
    private IPurchaseRecordsService purchaseRecordsService;

    /**
     * 查询采购记录管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:records1:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseRecords purchaseRecords) {
        startPage();
        List<PurchaseRecords> list = purchaseRecordsService.selectPurchaseRecordsList(purchaseRecords);
        return getDataTable(list);
    }

    /**
     * 导出采购记录管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:records1:export')")
    //@Log(title= "采购记录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseRecords purchaseRecords) {
        List<PurchaseRecords> list = purchaseRecordsService.selectPurchaseRecordsList(purchaseRecords);
        ExcelUtil<PurchaseRecords> util = new ExcelUtil<PurchaseRecords>(PurchaseRecords.class);
        util.exportExcel(response, list, "采购记录管理数据");
    }

    /**
     * 获取采购记录管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:records1:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId) {
        return success(purchaseRecordsService.selectPurchaseRecordsByRecordId(recordId));
    }

    /**
     * 新增采购记录管理
     */
    //@PreAuthorize("@ss.hasPermi('system:records1:add')")
    //@Log(title= "采购记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseRecords purchaseRecords) {
        return toAjax(purchaseRecordsService.insertPurchaseRecords(purchaseRecords));
    }

    /**
     * 修改采购记录管理
     */
    //@PreAuthorize("@ss.hasPermi('system:records1:edit')")
    //@Log(title= "采购记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseRecords purchaseRecords) {
        return toAjax(purchaseRecordsService.updatePurchaseRecords(purchaseRecords));
    }

    /**
     * 删除采购记录管理
     */
    //@PreAuthorize("@ss.hasPermi('system:records1:remove')")
    //@Log(title= "采购记录管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds) {
        return toAjax(purchaseRecordsService.deletePurchaseRecordsByRecordIds(recordIds));
    }
}
